#include <iostream>
#include <unordered_map>
using namespace std;
typedef long long LL;

const int N = 3e5 + 10;

LL pre[N], a[N]; // pre[i] 表示[j + 1, pre[i]] 中对于j 都可选
LL dp[N]; // 1 - i 中最小的a[i] * (n - i + 1);

int main()
{
    int n; cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    dp[1] = a[1] * n;
    for(int i = 2; i <= n; i++) dp[i] = min(dp[i - 1], a[i] * (n - i + 1));
    unordered_map<int, int> mp;
    for(int j = 1, i = 1; j <= n; j++)
    {
        while(i <= n && mp[a[i]] == 0) 
        {
            mp[a[i]]++;
            i++;
        }
        pre[j] = i;
        mp[a[j]]--;
    }
    LL ans = 4e18;
    for(int j = 1; j <= n; j++)
    {
        ans = min(ans, dp[pre[j]] + a[j - 1] * (j - 1));
    }
    cout << ans << endl;
    return 0;
}